package com.henu.yizhiya.db;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import com.henu.R;
import com.henu.yizhiya.entity.Room;
import com.henu.yizhiya.util.RoomListAdapter;
import java.util.ArrayList;

//展示自习室信息
public class GetRoomsActivity extends AppCompatActivity {
    private DBManager manager;
    private ArrayList<RoomDB> room_list;
    private RoomListAdapter adapter;
    private ListView lv_rooms;
    private ImageButton room_return;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_room);

        room_return = (ImageButton) findViewById(R.id.room_return);
        //加载rooms适配器
        adapter = new RoomListAdapter(this);
        lv_rooms = (ListView) findViewById(R.id.lv_rooms);
        lv_rooms.setAdapter(adapter);

        manager = DBManager.getInstance(this);
        //获取某一栋楼的所有房间
        room_list = (ArrayList<RoomDB>) getIntent().getSerializableExtra("room_list");
        //显示信息
        room_list = manager.search(room_list.get(0).getR_num().charAt(0)+"");
        adapter.addAllData(room_list);
        adapter.notifyDataSetChanged();


        //返回事件
        room_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
